var Base64 = ecCom.WeaTools.Base64;
export class GetFormJson {

    /**
     * 设置接口返回的json,实现混列样式
     * perams data:接口返回的数据,object 
     * perams condition:condition的kek值,string 
     * perams isInitForm:是否初始化form,bool 
     * return data:重构后的json,obj 
     */
    setFormJson(data, form, condition, domkeys, colSpans, labelcols, fieldcols, callback, _this, isInitForm) {
        if (_.has(data, condition)) {
            data[condition] = data[condition] || [];
            if (data[condition].length > 0) {
                data[condition].map((c, index) => {
                    let _str = index;
                    let getData = [];
                    if (_.has(c, 'items')) {
                        let _index = -1;
                        c.items = c.items || [];
                        c.items.map((item, index) => {
                            let itemDomkey = item.domkey[0].replace(`_${_str}`, '');
                            if (itemDomkey == domkeys[0] || itemDomkey == domkeys[1]) {//暂时
                                item = {
                                    ...item,
                                    colSpan: colSpans[0],
                                    labelcol: labelcols[0],
                                    fieldcol: fieldcols[0]
                                };
                                //暂时接入，后面优化
                                if (itemDomkey == "remark") {
                                    _index = index;
                                    item = {
                                        ...item,
                                        colSpan: 1,
                                        labelcol: 4,
                                        fieldcol: 20
                                    };
                                }
                                if (itemDomkey == "remark" && item.viewAttr != 1) {
                                    item.value = Base64.decode(item.value);
                                }
                                getData.push(item);
                            } else {
                                item = {
                                    ...item,
                                    colSpan: colSpans[1],
                                    labelcol: labelcols[1],
                                    fieldcol: fieldcols[1]
                                };
                                if (index == 0) {
                                    item = {
                                        ...item,
                                        colSpan: colSpans[0],
                                        labelcol: labelcols[0],
                                        fieldcol: fieldcols[0]
                                    };
                                }
                                if(item.conditionType == "RICHTEXT" && item.viewAttr !=1){
                                    item.value = Base64.decode(item.value);
                                }
                                getData.push(item);
                            }
                        });
                        c.items = [];
                        c.items = c.items.concat(getData);
                        //将任务描述放最后一行,暂时接入，后面优化
                        if(_index !=-1){
                            let _item = c.items.splice(_index, 1);
                            c.items.push(_item[0]);
                            c.items[0].colSpan = colSpans[0];
                            c.items[0].labelcol = labelcols[0];
                            c.items[0].fieldcol = fieldcols[0];
                            
                        }
                       
                    }
                });
            }
            if (isInitForm) {
                if (callback) {
                    callback(data[condition], _this);
                }
                form && !form.isFormInit && form.initFormFields(data[condition]);
            } else {
                return data;
            }
        }
    }


}
export default new GetFormJson